"""
本页面三个大题，第一个函数型学生管理列表
其余两个题目都是水仙花数求法解
"""

info_list = []
import sys
import os
username = "123456"
password = "admin"
new_file = "info.txt"

print('hello world')
print('first')
print('please say love me in chinese')
print('hello who is ')


def load_info():
    global info_list
    try:
        f = open(new_file, "r", encoding="utf_8")
    except FileExistsError:
        f = open(new_file, "w", encoding="utf_8")
        f.write("[]")
        f.seek(0)
        f.close()

    info = f.read()
    info_list = eval(info)
    f.close()


def save_info():
    f = open(new_file, "w", encoding="utf_8")
    f.write(str(info_list))
    f.close()


def welcome():
    print("-------------学生管理器----------------")
    print("--1.添加学生信息")
    print("--2.修改学生信息")
    print("--3.删除学生信息")
    print("--4.查询学生信息")
    print("--5.查询所有信息")
    print("--6.退出系统")
    print("-" * 30)


def capture1():
    name = input("请输入想要添加的名字：")
    age = input("请输入年龄：")
    boy = input("请输入性别：")
    info_list.append({"name": name, "age": age, "boy": boy})


def capture2():
    name = input("请输入想要修改的学生名字：")
    for info in info_list:
        if name in info.values():
            age = input("请输入年龄:")
            boy = input("请输入性别:")
            info_list[info_list.index(info)] = {"name": name, "age": age, "boy": boy}
            print("修改成功")
            break
    else:
        print("查无此人")


def capture3():
    name = input("请输入想要删除的学生信息名字：")
    for info in info_list:
        if name in info.values():
            info_list.remove(info)
            print("删除成功")
            break
    else:
        print("没有你想要删除的人")


def capture4():
    name = input("请输入想要查询的学生信息名字")
    for info in info_list:
        if name in info.values():
            print("此人的信息为：%s" % info)
            break
        else:
            print("请输入正确的名字，查无此人")


def capture5():
    paw = input("请输入管理员账号：")
    uname = input("请输入管理员密码 ")
    if paw == password and uname == username:
        for info in info_list:
            for j in info.values():
                print(j, end="\t\t")

            print()

    else:
        print("【ERROR】账号或者密码输入错误")
        sys.exit()


def capture6():
    sign = input("【INFO】您确定要退出系统吗：回复yes 或 no")
    if sign == "yes"or sign == "":
        print("【INFO】系统已退出，欢迎再次光临")
        save_info()
        sys.exit()
    else:
        print("请输入正确的数字")


def capture():
    welcome()
    # if os.path.exists(new_file):
    #     load_info()
    # else:
    #     f = open(new_file, "w", encoding="utf_8")
    #     f.write("[]")
    #     f.close()
    load_info()
    while True:
        shu = int(input("请输入数字1-5"))
        if shu == 1:
            capture1()
        elif shu == 2:
            capture2()
        elif shu == 3:
            capture3()
        elif shu == 4:
            capture4()
        elif shu == 5:
            capture5()
        elif shu == 6:
            capture6()
        else:
            print("数字输入不正确")
if __name__ == "__main__":
    capture()


#
#
# for i in range(100, 10000):
#     if int(str(i)[0])**3 + int(str(i)[1])**3 + int(str(i)[2])**3 == i:
#         print(i)
# #
# for i in range(100, 1000):
#     if int(str(i)[0]) ** 3 + int(str(i)[1]) ** 3 + int(str(i)[2]) ** 3 == i:
#         print(i)
# #